import time

import allure
from page_base.page_base import Base
from page_element.el_lg import *
import logging



class PageLogin(Base):
    """登录页面"""
    def page_login(self, username, password):
        # 打开A3mall
        self.open_url(url)
        self.maximize_window()
        with allure.step(f"输入用户名: {username}"):
            self.send_keys(login_page.name_input, username)
        with allure.step(f"输入密码: {password}"):
            self.send_keys(login_page.pwd_input, password)
        time.sleep(7)
        with allure.step("点击登录按钮"):
            self.click(login_page.login_btn)

        logging.info('===============================================')
        # while 1:
        #     logging.info('************************')
        #     yzm = self.text(login_page.yzm_input)
        #     print(f'-----------111111111---------------{yzm}')
        #     if len(yzm) == 4:
        #         with allure.step("点击登录按钮"):
        #             self.click(login_page.login_btn)
        #             break

        try:
            dy_suess = self.text(login_page.dy_loginsess)
            if dy_suess == '龙果支付后台':
                logging.info('*******登录成功*******')
        except Exception as e:
            logging.info(f'=================={e}')
            dy_sy = self.text(login_page.dy_shouye)
            if dy_sy == '设为首页':
                logging.info('*****登录失败*****')

